import React, { useState } from 'react';
import { IFormItem, Itype } from '@/base-ui/form';
import http from '@/services/request';
import { Space, Button, Select } from 'antd';
import { Input } from 'antd';
import { RightOutlined, UpOutlined } from '@ant-design/icons';

const { Option } = Select;

const { Search } = Input;

/* 搜索区域 */
// 这是高级检索的搜索配置项，一般要和你的表格的列关联
export const PageSearchConfig: IFormItem[] = [
  {
    type: 'input' as Itype,
    label: '订单编号',
    name: 'id',
    placeholder: '请输入订单编号'
  },
  {
    type: 'input' as Itype,
    label: '收货人姓名',
    name: 'consigneeName',
    placeholder: '请输入收货人姓名'
  },
  {
    type: 'input' as Itype,
    label: '发货人联系电话',
    name: 'consignerPhone',
    placeholder: '请输入发货人联系电话	'
  },
  {
    type: 'input' as Itype,
    label: '货物名称',
    name: 'goodsName',
    placeholder: '请输入货物名称'
  },
  {
    type: 'input' as Itype,
    label: '货物数量',
    name: 'goodsQuantity',
    placeholder: '请输入货物数量'
  },
  {
    type: 'input' as Itype,
    label: '货物总价',
    name: 'goodsTotalPrice',
    placeholder: '请输入货物总价'
  },
  {
    type: 'input' as Itype,
    label: '运费',
    name: 'logisticsFee',
    placeholder: '请输入运费'
  },
  {
    type: 'input' as Itype,
    label: '实际付款金额',
    name: 'realPaymentAmount',
    placeholder: '请输入实际付款金额'
  },
  {
    type: 'input' as Itype,
    label: '收货地址',
    name: 'recepitAddress',
    placeholder: '请输入收货地址'
  },
  {
    type: 'input' as Itype,
    label: '备注',
    name: 'remark',
    placeholder: '请输入备注'
  }
];

//高级检索
export const UseSearch = (props: any) => {
  return (
    <Space style={{ float: 'right' }}>
      {props.isMoreSearchShow ? (
        <Button
          type="link"
          size="large"
          onClick={() => {
            props.setisMoreSearchShow(false);
            props.setsearchMore(false);
          }}
        >
          收起
          <UpOutlined />
        </Button>
      ) : (
        <Button
          type="link"
          size="middle"
          onClick={() => {
            props.setisMoreSearchShow(true);
            props.setsearchMore(true);
          }}
        >
          高级检索
          <RightOutlined style={{ marginLeft: '1px' }} />
        </Button>
      )}
    </Space>
  );
};

// 这里是模糊查询 根据xxx进行查询
export const SearchSelector = (props: any) => {
  const [searchid, setsearchid]: any = useState('consigneeName');
  return (
    <div
      style={{
        display: 'inline-block',
        width: '380px',
        marginBottom: 10,
        marginRight: 10,
        float: 'right'
      }}
    >
      <Select
        defaultValue={Options[1].label}
        style={{ width: 100 }}
        defaultActiveFirstOption
        onSelect={(value: string, option: any) => {
          setsearchid(option.key);
        }}
      >
        {Options.map((i) => (
          <Option value={i.label} key={i.value} children={null} />
        ))}
      </Select>
      <Search
        placeholder="请输入您要查的数据"
        onSearch={(e) => {
          if (e.trim() === '') {
            http.get('/zk/dispatchOrderLogistics/list/1/10').then((res) => {
              props.dataSource(res.data.records);
            });
            return;
          }
          switch (searchid) {
            case 'consigneeName': {
              http(`/zk/dispatchOrderLogistics/list/consigneeName/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            case 'consignerPhone': {
              http(`/zk/dispatchOrderLogistics/list/consignerPhone/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            case 'id': {
              http(`/zk/dispatchOrderLogistics/get/${e}`).then((res) => {
                props.dataSource([res.data]);
              });
              break;
            }
            default: {
              break;
            }
          }
        }}
        style={{ width: '280px' }}
        enterButton
      />
    </div>
  );
};
export const Searchdow = () => {
  return;
};

const Options = [
  { label: '收货人名称', value: 'consigneeName', onClick: (e: any) => { } },
  { label: '发货人联系电话', value: 'consignerPhone', onClick: (e: any) => { } },
  { label: 'ID', value: 'id', onClick: (e: any) => { } }
];

/* 表格区域 */

//复选框的接口
export interface DataType {
  id: number;
  key: React.Key;
  name: string;
  age: number;
  address: string;
}
